var Pusher ={
		send :function(){

			if($("#mssage").val()==""){
				$("#showbox").html("消息内容！");
				$("#showdiv").removeClass("alert alert-success margin-bottom-10");
				$("#showdiv").addClass("Metronic-alerts alert alert-danger fade in");
				$("#showdiv").show();
			}else{
				var id = $("#eventId").val();
				$.ajax({  
					"dataType" : 'json',  
					"data":{
						"id":id,
						"mssage":$("#mssage").val(),
						
					},
					"type" : "POST",  
					"url" : "admin/push/totagpush.json",
					"success" : function(data){
						Pusher.cleanAll();
						$("#showbox").html("发送成功");
						$("#showdiv").show();
					},
					"error":function(){
						Pusher.cleanAll();
						$("#showbox").html("发送失败，系统异常，稍后再试！");
						$("#showdiv").removeClass("alert alert-success margin-bottom-10");
						$("#showdiv").addClass("Metronic-alerts alert alert-danger fade in");
						$("#showdiv").show();
					}
				});  
			}
			
			
		},
		cleanAll :function(){
			$('option',  $("#userSelection")).each(function(element) {
				 $("#userSelection").multiselect('deselect', $(this).val());
			    });
			$("#mssage").val("");
		},
		init :function(){
			
			 $.ajax({
	    			contentType: "application/json;charset=UTF-8",
	     			data:{},
//	    			url:"admin/user/tolock.json",
	    			url:"admin/push/getuser.json",
	    			dataType : 'json',
//	    			async: false,    
	    			type:'POST',
	    			success : function(data) {
	    				for(var i=0;i<data.data.length;i++){
	    					var varItem ="<option value='"+data.data[i].id+"'>"+data.data[i].nickname+"</option>";
	    					$("#userSelection").append(varItem);
	    				}
//	    			$("#userSelection").multiselect('rebuild');
	    			$('#userSelection').multiselect({
	    				includeSelectAllOption: true,
			        	enableFiltering: true,
			        	maxHeight: 250
	    			});
	    			
	    			for (var i = 1; i <= 100; i++) {
						$('#example28').append('<option value="' + i + '">' + i + '</option>');
					}

			        $('#example28').multiselect({
			        	includeSelectAllOption: true,
			        	enableFiltering: true,
			        	maxHeight: 150
			        });
	    			},
	     			error :function(XMLHttpRequest, textStatus, errorThrown){
	     				alert(XMLHttpRequest.status);
                     alert(XMLHttpRequest.readyState);
                     alert(textStatus);
	     			}
	    		});
			
		},
		selectALL :function(){
			if($("#example21-toggle").html() =="选择所有"){
				
			   $('option', $("#userSelection")).each(function(element) {
				   $("#userSelection").multiselect('select', $(this).val());
				    });
				$("#example21-toggle").html("取消选择");
			}else{
				$('option',  $("#userSelection")).each(function(element) {
					 $("#userSelection").multiselect('deselect', $(this).val());
				    });
				
				$("#example21-toggle").html("选择所有");
			}
			
			
		}
		
}


$(document).ready(function() {
	$("#showdiv").hide();
	Pusher.init();
});
